<script setup>
import {ref,reactive} from 'vue'
const km=ref('')
const nr=ref('')
const dd =ref('')
const zt=ref(1)
const  list=reactive([])
function add(){
    
    if(km.value=='' || nr.value=='' || dd.value =='')
        alert("傻逼你什么都没有添加个蛋")
    else{
        list.push({科目:km.value,内容:nr.value,地点:dd.value,状态:zt.value})
        km.value=''
        nr.value=''
        dd.value=''
    }
}
function del(index){
    list.splice(index, 1)
}
</script>
<template>
<h1>阶段案例-学习计划表-Demo10</h1>
<div class="box">
    <div class="top">
        <div class="header">
            学习计划表
        </div>
        <div class="add">
            <div class="div1">
                <span>学习科目</span>
                <input type="text" class="inputa" placeholder="请输入学习科目" v-model="km"/>

            </div>
            <div class="div1">
                <span>学习内容</span>
                <input type="text" class="inputa" placeholder="请输入学习内容" v-model="nr"/>

            </div>
            <div class="div1">
                <span>学习地点</span>
                 <select v-model="dd">
                    <option value="自习室">自习室</option>
                    <option value="实验室">实验室</option>
                    <option value="图书馆">图书馆</option>
                </select>


            </div>
            <input type="button" class="but" value="添加" @click="add" />
        </div>
    </div>
    <table >
        <tr>
            <th>序号</th>
            <th>学习科目</th>
            <th>学习内容</th>
            <th>学习地点</th>
            <th>完成状态</th>
            <th>操作</th>
        </tr>
        <tr v-for="(item,index) in list">
            <td>{{index+1}}</td>
            <td>{{item.科目}}</td>
            <td>{{item.内容}}</td>
            <td>{{item.地点}}</td>
                    
            <td v-if="item.状态==1" class="tdflex" @click="item.状态=(item.状态+1)%2;">
                    <div class="finishN">
                        <div class="qiu">

                        </div>
                    </div>
                    <span>未完成</span>
            </td>
            <td v-else class="tdflex"  @click="item.状态=(item.状态+1)%2;">
                <div class="finishY">
                        <div class="qiu">

                        </div>
                    </div>
                    <span>已完成</span>
            </td>
            <td><button @click="del(index)">删除</button></td>
        </tr>
    </table>
</div>
</template>
<style scoped>
*{
    margin: 0;
    padding: 0;
}
.box{
    height: 800px;
    background-color: aliceblue;
    margin: 50px 50px;
    border-radius: 5px 5px 0px 0px;
}
.top{
    height: 150px;
     border-radius: 5px 5px 0px 0px;
}
.header{
    line-height: 40px;
    background-color: aqua;
    padding-left: 10px;
    border-radius: 5px 5px 0px 0px;
}
.add{
    height: 110px;
    background-color: aquamarine;
    display: flex;
    align-items: center;
    padding: 10px;
}
/* table{
    width: 100%;
    border-collapse: collapse;
    
}
tr{height: 30px;}
td th{border: 1px solid gray;}

tr:nth-child(even){
    background-color: wheat;
    border: 1px solid gray;
}
tr:first-child{
    border-bottom: 2px solid black;
} */
 table {
    width: 100%;
    border-collapse: collapse;
}

tr {
    height: 30px;
}

/* 修正选择器，同时选中 td 和 th */
td, th {
    border: 1px dashed gray;
    padding: 6px 12px; /* 增加内边距让内容不贴边 */
}

tr:nth-child(even) {
    background-color: wheat;
}

tr:first-child {
    border-bottom: 2px solid black;
    background-color: #f0f0f0; /* 给表头增加背景色区分 */
}

/* 可选：添加hover效果增强交互 */
tr:hover:not(:first-child) {
    background-color: #f5f5f5;
}
.div1{
    border:1px solie gray;
    width: 200px;
    display:flex;
    justify-content: left;
    line-height: 30px;
    height:30px;
    margin-right: 20px;

}
.div1 span{
    width:160px;
    background-color:ghostwhite;
    padding: 0px 5px;
    border-radius: 5px 0px 0px 5px;
}
.inputa{
    width:120px;
    outline:none;
    border: 0px;
    height: 30px;
    padding: 0px 5px;
    box-sizing: border-box;
    border-radius: 0px 5px 5px 0px;
}
.div1 select{
    width:120px;
    outline:none;
    border: 0px;
    height: 30px;
    padding: 0px 5px;
    box-sizing: border-box;
    border-radius: 0px 5px 5px 0px;
}
.but{
    width: 50px;
    height: 30px;
}
.finishN
{
    border-radius: 5px;
    width: 30px;
    height:11px;
    border: 1px solid gray;
    background-color: white;
    padding-left: 2px;
    margin-right: 10px;
}
.qiu{
    width:10px;
    height: 10px;
    background-color: gray;
    border-radius: 5px;
}
.finishY{
    border-radius: 5px;
    width:30px;
    height:11px;
    background-color:white;
    padding-left: 18px;
    margin-right: 10px;
    padding-right:5px;
    border: 1px solid gray;
}
.tdflex{
    display: flex;
    align-items: center;
    justify-content: center;
}
</style>